const ws = require('ws')

const websocket = new ws.Server({
    port:8000
})

// 监听事件
websocket.on("open",()=>{
    console.log('open')
})

websocket.on("close",()=>{
    console.log('close')
})

websocket.on('error',()=>{
    console.log('error')
})

websocket.on('connection',(ws)=>{
    console.log('connection');
    ws.on('message',(msg)=>{
        websocket.clients.forEach(c => {
            c.send(msg)
        })
    })
})